<h2><img src="/images/monitor.png" align="left">Dashboard</h2>
<br/>

<% @projects.each do |p| -%>
<a href="/project/view/<%=p.id%>"><%=p.name%></a> (<a href="/task/select_project_index/<%=p.id%>">tasks</a>) | 
<% end -%>


<% if @invit!=[] %>
<h3><img src="/images/letter.png" align="left">Invitations</h3>

<% for i in @invit %>
<div id="inv<%=i.id%>">
<%=i.name%> invites you to join the project "<%=i.project.name%>"
<%= link_to_remote( "Accept", {:update => "inv"+i.id.to_s, :url =>{ :controller=> :invitation, :action => :accept, :id=>i.id },
 :loading  => visual_effect('appear', 'ind'+i.id.to_s),
 :success => {visual_effect('fade', 'ind'+i.id.to_s), visual_effect('fade','ind'+i.id.to_s)}},
 {:class=>"btnlnk"}) %>
<%= link_to_remote( "Decline", {:update => "inv"+i.id.to_s, :url =>{ :controller=> :invitation, :action => :decline, :id=>i.id },
 :loading  => visual_effect('appear', 'ind'+i.id.to_s),
 :success => {visual_effect('fade', 'ind'+i.id.to_s), visual_effect('fade','ind'+i.id.to_s)}},
 {:class=>"btnlnk"}) %>

<img id="ind<%=i.id%>" src="/images/loading.gif" style="display:none;">

</div>
<% end %>
<% end %>


<% if @projects.size == 0 -%>
Welcome.<br/>
You can now keep track of the tasks you have to do. They will belong to categories called "projects".<br/>
Each project can have its own group of users.<br/>
<br/>
Create a task now by clicking on tasks, in the menu above.<br/>

<% else -%>

<% if @deadlines.size>0 -%>
<h3><img src="/images/time2.png" align="left">Deadlines</h3>
<ul class="mylist">
<% for task in @deadlines -%>
<li><%= task.duedate %> <%= task.title %> <% if task.project != nil %>(<a href="/task/select_project_index/<%=task.project.id%>"><%= task.project.name %>)<%end%></a>

<% if(task.duedate != nil) -%>
<% if(task.duedate == Date.today) -%>
<div class="duetoday">today !</div>
<% elsif(task.duedate > Date.today and task.duedate <= Date.today+1) -%>
<div class="duetoday">tomorrow!</div>
<% elsif(task.duedate > Date.today and task.duedate <= Date.today+3) -%>
<div class="duenear"><%= time_ago_in_words(task.duedate+1) %></div>
<% elsif(task.duedate > Date.today) -%>
<div class="duefutur"><%= time_ago_in_words(task.duedate+1) %></div>
<% elsif(task.duedate < Date.today) -%>
<div class="duepast"><%= time_ago_in_words(task.duedate) + " ago !" %></div>
<% end -%>
<% end -%>

</li>
<% end -%>
</ul>
<% end -%>


<h3><img src="/images/important.png" align="left">Important tasks</h3>
<% if @important_tasks.size==0 -%>
You have no tasks.
<% else -%>
<ul class="mylist">
<% for task in @important_tasks -%>
<li>

<% if task.priority != nil -%>
<div class="priority p<%=task.priority%>"><%= task.priority %></div>
<% end -%>

<%= task.title %>

<% if task.project != nil -%>
(<a href="/task/select_project_index/<%=task.project.id%>"><%= task.project.name %></a>)
<% end -%>
</li>

<% end -%>
</ul>
<% end -%>

<% if @tasksdone1.size+@tasksdone2.size > 0-%>
<h3>Tasks done</h3>
Today and yesterday
<ul style="list-style-type:none;padding:0;font-size:small;">
<%= render(:partial=>'project/task', :collection=>@tasksdone1) %>
</ul>
Last week
<ul style="list-style-type:none;padding:0;font-size:small;">
<%= render(:partial=>'project/task', :collection=>@tasksdone2) %>
</ul>
<% end -%>


<h3>All your projects with 5 important active tasks assigned to you</h3>
<p>Click on a folder to see the 5 most important tasks.<br/>
Click on a project name to see all the tasks to do for this project.</p>
<%
@projects.each { |p|%>

	<h4><a href="#" onclick="$('p_<%=p.id%>').toggle();return false;"><img src="/images/folder.png" align="left"></a> <%= link_to(p.name.upcase, {:controller => 'task', :action => 'select_project_index', :id => p.id})  %> <%=Task.count :all, :conditions=>"done='0' and project_id=#{p.id}"%> tasks</h4>
	
	<div id="p_<%=p.id%>" style="display:none">
	
	<% tasks = p.tasks.find(:all, :conditions=>"done='0' and user_id='#{session['user']['id']}' and title!=''", :order => "priority, `order`", :limit => 5) -%>
	
	<% if(tasks.size==0) -%>
	(no task for you)<br/>
	<% else -%>
	<ul class="mylist">
	<% for task in tasks -%>
	<li><%= task.title %></li>
	<% end -%>
	</ul>
	<% end -%>
	
	</div>
	
<%	} # each project

end # if one project exists
-%>
